package com.zllkj.mm.base;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.zllkj.mm.AppManager;

import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.Nullable;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import rx.Subscription;
import rx.subscriptions.CompositeSubscription;

/**
 * Created by librabin on 17/2/8.
 */

public abstract class BaseAppActivity extends BaseActivity {


    private LocalBroadcastManager mLocalBroadcastManager;
    private BroadcastReceiver mExitBroadcastReceiver;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //添加当前activity到堆栈式管理
//        AppManager.getAppManager().addActivity(this);
//        //友盟
//        PushAgent.getInstance(this).onAppStart();

//        mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);
//        mExitBroadcastReceiver = new ExitBroadcastReceiver();
//        mLocalBroadcastManager.registerReceiver(mExitBroadcastReceiver,
//                new IntentFilter(MDConstant.EXIT_APP));



    }


    @Override
    protected void onResume() {
        super.onResume();
//        //友盟
//        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
//        //友盟
//        MobclickAgent.onPause(this);
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        //rx取消订阅
        unSubscribe();
        //从堆栈式管理移除当前activity
        AppManager.getAppManager().removeActivity(this);
//        mLocalBroadcastManager.unregisterReceiver(mExitBroadcastReceiver);
    }

    //退出APP广播接收器
    public class ExitBroadcastReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
//            if (intent.getAction().equals(MDConstant.EXIT_APP)) {
//                //接收到退出消息
//                onReceiveExitMsg();
//            }
        }
    }

    //接收到退出消息
    public void onReceiveExitMsg() {
//        //显示被踢下线弹框
//        MDAppUtils.showKickOutDialog(this);
    }

    //rx总线
    private CompositeSubscription compositeSubscription = new CompositeSubscription();

    //rx总线里添加订阅
    public void addSubscribe(Subscription subscription) {
        compositeSubscription.add(subscription);
    }

    //rx取消订阅
    public void unSubscribe() {
        if (compositeSubscription != null) {
            compositeSubscription.unsubscribe();
            compositeSubscription = null;
        }
    }


}
